<?php

/**
 * @Author: Wang chunsheng  email:2192138785@qq.com
 * @Date:   2023-04-24 13:54:59
 * @Last Modified by:   Wang chunsheng  email:2192138785@qq.com
 * @Last Modified time: 2023-05-07 11:58:35
 */

namespace Common;

use Common\Models\sys\JwtService;
use Helpers\DebugHelper;

abstract class AdminController extends AbstractController
{
    /**
     * 不用进行登录验证的方法
     * 例如： ['index', 'update', 'create', 'view', 'delete']
     * 默认全部需要验证
     *
     * @var array
     */
    protected array $authOptional = [];

    protected function getAttribute($key)
    {
        return $key;
    }

    public function writeJson($statusCode = 200, $result = null, $msg = null): array
    {
        if ($result && is_array($result) && key_exists('status', $result)) {
            // 服务中包含了状态，直接返回
            $data = $result;
        } else {
            $data = [
                'code' => $statusCode,
                'data' => $result,
                'message' => $msg,
            ];
        }

        return $data;
    }

}
